﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SemPlayGen.Repository.Repositories;
using System.Data;
using SemPlayGen.Logic;

namespace SemPlayGen.Website
{
    public partial class SearchPlaylists : System.Web.UI.Page
    {
        protected class listItem
        {
            public int ID { get; set; }
            public string Name { get; set; }

            public listItem(int id, string name)
            {
                id = ID;
                Name = name;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ArtistTypesRepository artistTypesRepo = new ArtistTypesRepository();
            GenresRepository genresRepo = new GenresRepository();
            MusicTypesRepository musicTypesRepo = new MusicTypesRepository();
            SongsRepository songsRepo = new SongsRepository();
            SignalsRepository signalsRepo = new SignalsRepository();

            if (!IsPostBack)
            {
                ddlArtistType.DataSource = artistTypesRepo.GetAll();
                ddlArtistType.DataBind();

                ddlGenre.DataSource = genresRepo.GetAll();
                ddlGenre.DataBind();

                ddlMusicType.DataSource = musicTypesRepo.GetAll();
                ddlMusicType.DataBind();


                IList<listItem> lstLength = new List<listItem>();
                lstLength.Add(new listItem(5, "5"));
                lstLength.Add(new listItem(10, "10"));
                lstLength.Add(new listItem(20, "20"));
                lstLength.Add(new listItem(30, "30"));
                lstLength.Add(new listItem(50, "50"));
                lstLength.Add(new listItem(100, "100"));

                ddlPlaylistlength.DataSource = lstLength;
                ddlPlaylistlength.DataBind();
            }
        }

        protected void ddl_DataBound(object sender, EventArgs e)
        {
            DropDownList ddl = (DropDownList)sender;
            if (ddl.Items.FindByValue("0") == null)
                ddl.Items.Insert(0, new ListItem("< Сите >", ""));
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            gvPlaylist.DataSource = Semantics.GeneratePlaylist((ddlPlaylistlength.SelectedValue != "" ? Convert.ToInt32(ddlPlaylistlength.SelectedValue) : 100)
                , ddlArtistType.SelectedItem.Value
                , ddlMusicType.SelectedItem.Value
                , ddlGenre.SelectedItem.Value);
            gvPlaylist.DataBind();
        }
    }
}